package com.wc.alorithm_blue_bridge._二分.Q3611;

import java.util.*;
import java.io.*;

/**
 * @Author congege
 * @Description 冒险者公会
 * https://www.lanqiao.cn/problems/3611/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/23-22:45
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] powers = new int[n];
        for (int i = 0; i < n; i++) {
            powers[i] = sc.nextInt();
        }

        Arrays.sort(powers);
        long ans = 0;
        while (m-- > 0) {
            int k = sc.nextInt();

            int[] tasks = new int[k];
            for (int i = 0; i < k; i++) {
                tasks[i] = sc.nextInt();
            }
            Arrays.sort(tasks);
            if (n < k) {
                ans = -1;
                break;
            }
            int i = 0;
            int j = 0;
            long tmpAns = 0;
            for (; i < k && j < n; i++) {
                // 找到一个刚好大于的位置
                j = search(tasks[i], powers, j, n - 1);
                if (j >= n) {
                    ans = -1;
                    break;
                }
                tmpAns += powers[j];
                j++;
            }

            if (i != k) {
                ans = -1;
            }
            if (ans == -1) {
                break;
            }
            ans = Math.max(ans, tmpAns);
        }

        System.out.println(ans);
    }

    static public int search(int val, int[] array, int left, int right) {
        int mid;
        while (left <= right) {
            mid = left + (right - left) / 2;
            if (array[mid] > val) {
                right = mid - 1;
            } else if (array[mid] < val) {
                left = mid + 1;
            } else {
                return mid;
            }
        }

        return left;
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (Exception e) {
                return -1;
            }
            return (int) in.nval;
        }
    }
}
